package main

import (
	"apibe/grpc/roads/go/rpc"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/keepalive"
	"net"
	"time"
)

func main() {

	// grpc
	{
		listen, err := net.Listen("tcp", ":8011")
		if err != nil {
			fmt.Printf("监听端口失败： %v \n", err.Error())
			return
		}
		// 创建grpc服务器
		kp := keepalive.ServerParameters{Timeout: 1 * time.Second, Time: 10 * time.Second} // 10s1ping保活
		s := grpc.NewServer(grpc.KeepaliveParams(kp))
		//注册服务
		rpc.RegisterRoadsServer(s, &rpc.Server{})
		err = s.Serve(listen)
		if err != nil {
			fmt.Printf("服务启动失败: %s \n", err)
			return
		}
	}

	// http
	//{
	//	http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
	//		// Respond with "pong" when /ping is accessed
	//		fmt.Fprintf(w, "pong\n")
	//	})
	//	listen, err := net.Listen("tcp", ":8011")
	//	err = http.Serve(listen, nil)
	//	if err != nil {
	//		fmt.Printf("启动失败")
	//	}
	//}
}
